package cn.lic.tool.poi.excel.function.impl;

import java.util.Objects;

import org.apache.poi.ss.usermodel.Cell;

import com.alibaba.fastjson.JSONObject;

import cn.lic.tool.poi.excel.ParserUtils;
import cn.lic.tool.poi.excel.function.AbstractFunction;
import cn.lic.tool.poi.excel.function.IFunction;
import cn.lic.tool.poi.excel.function.IFunctionArgument;
import cn.lic.tool.poi.excel.function.IValue;
import cn.lic.tool.poi.excel.function.IValue.Type;
import cn.lic.tool.poi.excel.function.Range;

/**
 * 接收两个参数, 如果相等则返回true,否则返回false
 * @author Administrator
 *
 */
public class Equal extends AbstractFunction {
	public Equal() {}
	public Equal(IFunctionArgument[] args) {
		 this.args = args;
	}

	@Override
	public IFunction build(IFunctionArgument[] args) {
		return new Equal(args);
	}

	@Override
	public IValue execute(JSONObject ctx) {
		Object arg0 = this.getArg(0, ctx).castValue(Type.OBJECT);
		Object arg1 = this.getArg(1, ctx).castValue(Type.OBJECT);
		return IValue.buildSValue(Objects.equals(arg0, arg1));
	}

	@Override
	public Range execute(JSONObject ctx, Cell cell) {
		IValue rs = this.execute(ctx);
		ParserUtils.setCellValue(cell, rs);
		return null;
	}
}
